<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="130px">
      <el-form-item label="考生编号" prop="candidateId">
        <el-input
          v-model="queryParams.candidateId"
          placeholder="请输入考生编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="准考证号" prop="examNumber">
        <el-input
          v-model="queryParams.examNumber"
          placeholder="请输入准考证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份验证结果" prop="identityVerificationResult">
        <el-select v-model="queryParams.identityVerificationResult" placeholder="请选择身份验证结果" clearable>
          <el-option
            v-for="dict in selectList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['system:identity:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['system:identity:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['system:identity:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:identity:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['system:identity:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-view"
          size="mini"
          @click="clickIdCard"
        >识别</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-refresh-right"
          size="mini"
          @click="handleGenerateDbIdentityList"
          v-hasPermi="['system:identity:edit']"
        >生成递补资格审查名单</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="identityList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="" align="center" prop="id" />-->
      <el-table-column label="考生编号" align="center" prop="candidateId" width="120"/>
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="gender" />
      <el-table-column label="身份证号" align="center" prop="idCard" width="200"/>
      <el-table-column label="准考证号" align="center" prop="examNumber" width="120"/>
      <el-table-column label="行测成绩" align="center" prop="administrativeAptitudeScore" />
      <el-table-column label="申论成绩" align="center" prop="essayScore" />
      <el-table-column label="专业科目成绩" align="center" prop="professionalSubjectScore" width="120"/>
      <el-table-column label="总成绩" align="center" prop="totalScore" />
      <el-table-column label="专业技能测试成绩" align="center" prop="professionalSkillTestScore" width="140"/>
      <el-table-column label="报考单位" align="center" prop="appliedUnit" width="180"/>
      <el-table-column label="报考职位" align="center" prop="appliedPosition" width="200"/>
      <el-table-column label="招考人数" align="center" prop="recruitmentNumber" />
      <el-table-column label="面试比例" align="center" prop="interviewRatio" />
      <el-table-column label="排名" align="center" prop="ranking" />
      <el-table-column label="毕业院校" align="center" prop="graduationSchool" width="180"/>
      <el-table-column label="是否增加专业技能测试" align="center" prop="hasProfessionalSkillTest" width="150"/>
      <el-table-column label="职位类别" align="center" prop="positionCategory" />
      <el-table-column label="身份验证结果" align="center" prop="identityVerificationResult" width="120">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.identityVerificationResult != null" :type="scope.row.identityVerificationResult == '未通过' ? 'danger' : 'success'">{{scope.row.identityVerificationResult}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="修改时间" align="center" prop="modifyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.modifyTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="150">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:identity:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:identity:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改四级联考身份验证对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="考生编号" prop="candidateId">
              <el-input v-model="form.candidateId" placeholder="请输入考生编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="gender">
              <el-input v-model="form.gender" placeholder="请输入性别" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="身份证号" prop="idCard">
              <el-input v-model="form.idCard" placeholder="请输入身份证号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="准考证号" prop="examNumber">
              <el-input v-model="form.examNumber" placeholder="请输入准考证号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报考单位" prop="appliedUnit">
              <el-input v-model="form.appliedUnit" placeholder="请输入报考单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报考职位" prop="appliedPosition">
              <el-input v-model="form.appliedPosition" placeholder="请输入报考职位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="毕业院校" prop="graduationSchool">
              <el-input v-model="form.graduationSchool" placeholder="请输入毕业院校" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="增加专业技能测试" prop="hasProfessionalSkillTest">
              <el-input v-model="form.hasProfessionalSkillTest" placeholder="请输入是否增加专业技能测试" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="职位类别" prop="positionCategory">
              <el-input v-model="form.positionCategory" placeholder="请输入职位类别" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="编号" prop="registrationId">
              <el-input v-model="form.bianhao" placeholder="请输入编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="身份验证结果" prop="identityVerificationResult">
              <el-radio v-model="form.identityVerificationResult" label="通过">通过</el-radio>
              <el-radio v-model="form.identityVerificationResult" label="未通过">未通过</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="考生照片" prop="photoPath">
              <div v-if="form.idCard">
                <img :src="photoUrl + form.idCard + '.jpg'"  style="vertical-align: bottom; width: 100px; height: 140px;" />
<!--                                <el-button style="margin-left:20px" type="danger" @click="deletephoto(form.idCard)">删除</el-button>-->
              </div>
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定 并 打 印</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-checkbox v-model="upload.updateSupport" />更新已存在数据
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <div style="display: none">
      <div id="prints">
        <div>
          <div style="padding: 20px 0 0 0;font-weight: 600;">
            <div style="margin-bottom: 20px;">编号：{{printContent.count}}</div>
            <div style="margin: auto;">
              <div style="text-align: center;font-size: 26px">{{printContent.content}}</div>
              <div style="text-align: center;margin-top: 12px;font-size: 24px">体能测评表</div>
            </div>
          </div>
          <div style="border: 3px solid #000;margin-top: 10px;">
            <div style="border-top: 1px solid #000;height: 49mm;display: flex;width: 100%;">
              <div style="width: calc(100% - 35mm);height: 100%;">
                <div style="display: flex;width: 100%;height:25mm;line-height: 25mm;">
                  <div style="width: 30%;border-right: 1px solid #000;text-align: center;">
                    <span>考生编号</span>
                  </div>
                  <div style="border-right: 1px solid #000;text-align: center;width: 70%;">
                    <span>{{form.bianhao}}</span>
                  </div>
                </div>
                <div style="display: flex;width: 100%;height:24mm;line-height: 24mm">
                  <div style="width: 30%;background-color: #e6e6e6;border-right: 1px solid #000;-webkit-print-color-adjust: exact;"
                       v-show="datebirth > 30">
                    <div class="title-namea">年龄（周岁）</div>
                  </div>
                  <div style="width: 30%;border-right: 1px solid #000;"
                       v-if="datebirth < 30 || datebirth == 30">
                    <div class="title-namea">年龄（周岁）</div>
                  </div>
                  <div style="width:20%;">
                    <div class="title-namea">{{ datebirth }}</div>
                  </div>
                  <div
                    style="width: 30%;background-color: #e6e6e6;border-right: 1px solid #000;border-left: 1px solid #000;-webkit-print-color-adjust: exact;"
                    v-if="datebirth > 30">
                    <div class="title-namea">性别</div>
                  </div>
                  <div style="width: 30%;border-right: 1px solid #000;border-left: 1px solid #000;"
                       v-if="datebirth < 30 || datebirth == 30">
                    <div class="title-namea">性别</div>
                  </div>
                  <div style="width: 20%;border-right: 1px solid #000;">
                    <div class="title-namea">{{ this.form.gender }}</div>
                  </div>
                </div>
              </div>

              <div style="width: 35mm;">
                <img :src="photoUrl + form.idCard + '.jpg'" @error="handleImageError"  style="width: 34mm;height: 48mm;margin: 2px 0 0 2px;"
                />
              </div>
            </div>


            <div style="display: flex;text-align: center;">
              <div style="border-right: 1px solid #000;width: calc((100% - 35mm) * 0.3)">
                <div class="title-name">体能测评标准</div>
              </div>
              <div style="width: calc(100% - (100% - 35mm) * 0.3);">
                <div class="title-name">
                  <span v-if="datebirth < 31 && this.form.gender == '男'">
                    <span v-if="form.positionCategory == null || form.positionCategory.includes('警务技术类')  || (form.positionCategory.includes('特警')||
                form.positionCategory.includes('突击')   || form.positionCategory.includes('狙击')  ||
                form.positionCategory.includes('搏击')  || form.positionCategory.includes('排爆') || form.positionCategory.includes('警务')) &&  form.hasProfessionalSkillTest == '是'">
                      纵跳摸高≥265厘米；10米×4往返跑≤13″1
                    </span>
                    <span v-else>纵跳摸高≥265厘米；10米×4往返跑≤13″1 ；1000米跑≤4′25″</span>
                  </span>
                  <span v-if="datebirth >= 31 && this.form.gender == '男'">
                    <span v-if="form.positionCategory == null  || form.positionCategory.includes('警务技术类') || (form.positionCategory.includes('特警') ||
                form.positionCategory.includes('突击')   || form.positionCategory.includes('狙击')  ||
                form.positionCategory.includes('搏击')  || form.positionCategory.includes('排爆')|| form.positionCategory.includes('警务')) &&  form.hasProfessionalSkillTest == '是'">
                      纵跳摸高≥265厘米；10米×4往返跑≤13″4
                    </span>
                    <span v-else>纵跳摸高≥265厘米；10米×4往返跑≤13″4；1000米跑≤4′35″</span>
                  </span>
                  <span v-if="datebirth < 31 && this.form.gender == '女'">
                    <span v-if="form.positionCategory == null  || form.positionCategory.includes('警务技术类') || (form.positionCategory.includes('特警')||
                form.positionCategory.includes('突击')   || form.positionCategory.includes('狙击')  ||
                form.positionCategory.includes('搏击')  || form.positionCategory.includes('排爆') || form.positionCategory.includes('警务')) &&  form.hasProfessionalSkillTest == '是'">
                     纵跳摸高≥230厘米；10米×4往返跑≤14″1
                    </span>
                    <span v-else>纵跳摸高≥230厘米；10米×4往返跑≤14″1；800米跑≤4′20″</span>
                  </span>
                  <span v-if="datebirth >= 31 && this.form.gender == '女'">
                    <span v-if="form.positionCategory == null  || form.positionCategory.includes('警务技术类') || (form.positionCategory.includes('特警')||
                form.positionCategory.includes('突击')   || form.positionCategory.includes('狙击')  ||
                form.positionCategory.includes('搏击')  || form.positionCategory.includes('排爆') || form.positionCategory.includes('警务')) &&  form.hasProfessionalSkillTest == '是'">
                      纵跳摸高≥230厘米；10米×4往返跑≤14″4
                    </span>
                    <span v-else>纵跳摸高≥230厘米；10米×4往返跑≤14″4；800米跑≤4′30″</span>
                  </span>
                </div>
              </div>
            </div>

            <div style="display: flex;border-top: 1px solid #000;padding-left: 10px;
            height: 60px;line-height: 60px;font-weight: 600;font-size: 18px;">
              <div style="width: 40%;">资格审查结果登记：</div>
              <div style="width: 30%;">初审人：</div>
              <div style="width: 30%;">复审人：</div>
            </div>

            <div style="display: flex;font-size: 18px">
              <div style="width: 40%;">
                <div class="title-names">体能测评</div>
              </div>
              <div class="title-left" style="width: calc(20% - 1px);">
                <div class="title-names">成绩</div>
              </div>
              <div class="title-left" style="width: 20%;">
                <div class="title-names">裁判员签字</div>
              </div>
              <div class="title-left" style="width: 20%;">
                <div class="title-names">监督员签字</div>
              </div>
            </div>

            <div style="display: flex;">
              <div style="width: 10%;">
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;">1</div>
                <div class="title-name">2</div>
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;">3</div>
                <div class="title-name">4</div>
                <div>
                  <div class="title-name"
                       style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;">5</div>
                  <div class="title-name">6</div>
                </div>
              </div>
              <div class="title-left" style="width: 30%;">
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;">男子纵跳摸高</div>
                <div class="title-name">女子纵跳摸高</div>
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;">男子10米×4往返跑
                </div>
                <div class="title-name">女子10米×4往返跑</div>
                <div>
                  <div class="title-name"
                       style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;">男子1000米跑</div>
                  <div class="title-name">女子800米跑</div>
                </div>
              </div>
              <div class="title-left" style="width: calc(20% - 1px);">
                <div class="title-name"
                     style="padding:0 5px 0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                <div class="title-name"></div>
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact"></div>
                <div class="title-name"></div>
                <div v-if="form.positionCategory == null  || form.positionCategory.includes('警务技术类')  || (form.positionCategory.includes('特警')||
                form.positionCategory.includes('突击')   || form.positionCategory.includes('狙击')  ||
                form.positionCategory.includes('搏击')  || form.positionCategory.includes('排爆') || form.positionCategory.includes('警务'))
                &&  form.hasProfessionalSkillTest == '是'">
                  <div class="title-name"
                       style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;">
                    <img src="@/assets/images/免测.png" style="width: 40px;" />
                  </div>
                  <div class="title-name">
                    <img src="@/assets/images/免测.png" style="width: 40px;" />
                  </div>

                </div>
                            <div v-else>
                              <div class="title-name"
                                   style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                              <div class="title-name"></div>
                                </div>
              </div>
              <div class="title-left" style="width: 20%;">
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                <div class="title-name"></div>
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                <div class="title-name"></div>
                <div>
                  <div class="title-name"
                       style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                  <div class="title-name"></div>
                </div>
              </div>
              <div class="title-left" style="width: 20%">
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                <div class="title-name"></div>
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                <div class="title-name"></div>
                <div>
                  <div class="title-name"
                       style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                  <div class="title-name"></div>
                </div>
              </div>
            </div>

            <div style="display: flex;border-top: 1px solid #000;padding-left: 10px;
            height: 90px;font-weight: 600;font-size: 18px;">
              <div style="width: 35%;border-right: 1px solid #000;">
                <div style="margin-top: 20px">体能测评</div>
                <div style="margin-top: 5px">结果登记</div>
              </div>
              <div style="width: calc(25% - 2px);border-right: 1px solid #000;line-height: 90px;margin-left: 10px">裁判长：</div>
              <div style="width: calc(40% + 2px);margin-left: 10px">
                <div style="margin-top: 20px;">考生签字确认：</div>
                <div style="margin-top: 5px">身份证号：</div>
              </div>
            </div>
          </div>

          <div style="margin: 5px 0px;font-size: 17px;">
            <div class="text">注：</div>
            <div class="text">男子30岁(含)以下测评标准：纵跳摸高≥265厘米；10米×4往返跑≤13″1；1000米跑≤4′25″；</div>
            <div class="text">男子31岁(含)以上测评标准：纵跳摸高≥265厘米；10米×4往返跑≤13″4；1000米跑≤4′35″；</div>
            <div class="text">女子30岁(含)以下测评标准：纵跳摸高≥230厘米；10米×4往返跑≤14″1；800米跑≤4′20″；</div>
            <div class="text">女子31岁(含)以上测评标准：纵跳摸高≥230厘米；10米×4往返跑≤14″4；800米跑≤4′30″；</div>
            <div class="text">年龄计算时间截止到参加体能测评当月。</div>
            <!--            <div class="text">警务技术职位测查10米×4往返跑和纵跳摸高项目，其它职位测查全部3个项目。</div>-->
            <div class="text">未达到测评标准，不合格。</div>
            <div style="float: right;margin-top: -10px;margin-right: 10px;">
              <img style="width: 180px;height: 60px;" :src="barcodeUrl + form.idCard + '.png'" @error="handleImageError" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import printJS from "print-js";
import { listIdentity, getIdentity, delIdentity, addIdentity, updateIdentity, generateDbIdentityList,getPrint,findRiQi } from "@/api/system/identity";
import { getToken } from "@/utils/auth";

export default {
  name: "Identity",
  data() {
    return {
      datebirth:"",
      photoUrl: process.env.VUE_APP_BASE_API + "/profile/",
      barcodeUrl: process.env.VUE_APP_BASE_API + "/profile/barcode/",
      printContent:{},
      riqi:{},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 四级联考身份验证表格数据
      identityList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        candidateId: null,
        name: null,
        idCard: null,
        examNumber: null,
        appliedUnit: null,
        appliedPosition: null,
        ranking: null,
        hasProfessionalSkillTest: null,
        positionCategory: null,
        identityVerificationResult: null,
        modifyTime: null
      },
      selectList: [{
        value: '通过',
        label: '通过'
      }, {
        value: '未通过',
        label: '未通过'
      }],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        idCard: [
          { required: true, message: "身份证号不能为空", trigger: "blur" }
        ],
        examNumber: [
          { required: true, message: "准考证号不能为空", trigger: "blur" }
        ],
      },
      // 导入相关参数
      upload: {
        title: "身份验证数据导入",
        open: false,
        updateSupport: false,
        isUploading: false,
        headers: { Authorization: "Bearer " + getToken() },
        url: process.env.VUE_APP_BASE_API + "/system/identity/importData"
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleImageError(e) {
      // 设置一个空白图片作为替代，而不是隐藏元素
      e.target.src = '';
    },
    clickIdCard() {
      axios.get('http://127.0.0.1:19196/readcard')
        .then((res) => {
          let idCard = res.data.certNumber
          console.log(idCard)
          this.queryParams.pageNum = 1;
          this.queryParams.idCard = idCard;
          this.loading = true;
          listIdentity(this.queryParams).then(response => {
            this.identityList = response.rows;
            this.total = response.total;
            this.loading = false;
            // 检查结果数量是否为1，如果是则弹出修改窗口
            if (this.identityList.length === 1) {
              this.handleUpdate(this.identityList[0]);
            }else{
              this.$message.error('未查询到此人');
            }
            this.queryParams = {}
            this.getList()
          });
        })
    },
    print() {
      const style = '@page {margin:0 10mm;}'
      printJS({
        //  设置打印区域id
        printable: "prints",
        type: "html",
        // header: '标题',
        // headerStyle: 'text-align:center; font-size: 24px; font-weight: bold; color: blue;', // 标题样式
        // targetStyles: ["*"],
        targetStyles: ["*", "#title"],
        style: style,
      });
    },
    /** 查询四级联考身份验证列表 */
    getList() {
      this.loading = true;
      listIdentity(this.queryParams).then(response => {
        this.identityList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        candidateId: null,
        name: null,
        gender: null,
        idCard: null,
        examNumber: null,
        administrativeAptitudeScore: null,
        essayScore: null,
        professionalSubjectScore: null,
        totalScore: null,
        professionalSkillTestScore: null,
        appliedUnit: null,
        appliedPosition: null,
        recruitmentNumber: null,
        interviewRatio: null,
        ranking: null,
        graduationSchool: null,
        hasProfessionalSkillTest: null,
        positionCategory: null,
        isAlternate: null,
        qualificationReviewResult: null,
        identityVerificationResult: null,
        physicalTestResult: null,
        finalResult: null,
        modifyTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加四级联考身份验证";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      findRiQi().then(response => {
        this.riqi = response.data;
      })
      this.reset();
      const id = row.id || this.ids
      getIdentity(id).then(response => {
        this.form = response.data;
        this.form.photoPath = response.data.photoPath; // 设置照片路径
          // 计算年龄
          const idCard = response.data.idCard;
          if (idCard) {
            const birthYear = parseInt(idCard.substring(6, 10));
            const birthMonth = parseInt(idCard.substring(10, 12));
            const birthDay = parseInt(idCard.substring(12, 14));
            const birthDate = new Date(birthYear, birthMonth, birthDay);

            setTimeout(() => {

              if (this.riqi) {
                const targetDate = new Date(this.riqi.nian, this.riqi.yue, this.riqi.ri); // 2025年3月31日
                console.log(targetDate,'targetDate')
                let age = targetDate.getFullYear() - birthDate.getFullYear();
                const monthDiff = targetDate.getMonth() - birthDate.getMonth();
                if (monthDiff < 0 || (monthDiff === 0 && targetDate.getDate() < birthDate.getDate())) {
                  age--;
                }
                this.datebirth = age;
              }
            },100)
          }
        this.open = true;
        this.title = "修改四级联考身份验证";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (!this.form.identityVerificationResult) {
            this.$modal.msgError("请录入身份验证结果再保存打印");
            return;
          }
          if (this.form.id != null) {
            updateIdentity(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              // this.getList();
              getPrint().then(response => {
                this.printContent = response.data;
                setTimeout(() => {
                  this.print()
                },100)
              })
            });
          } else {
            addIdentity(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除四级联考身份验证编号为"' + ids + '"的数据项？').then(function() {
        return delIdentity(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/identity/export', {
        ...this.queryParams
      }, `四级联考身份验证数据_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "四级联考身份验证数据导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('system/identity/importTemplate', {
      }, `四级联考身份验证数据导入模板.xlsx`);
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },

    /** 生成递补身份验证名单 */
    handleGenerateDbIdentityList() {
      this.$modal.confirm('确认生成递补资格审查名单？此操作将根据不合格考生，从成绩合格名单中递补考生。').then(() => {
        return generateDbIdentityList();
      }).then(response => {
        this.$modal.msgSuccess(response.msg || "生成递补资格审查名单成功");
        this.getList();
      }).catch(() => {});
    }
  }
};
</script>

<style>
/* 在样式表中设置无边框样式 */
.no-border-input .el-input__inner {
  border: none;
  border-radius: 0;
}

.dashboard-buttonWhite {
  min-width: 80px;
  color: #fff;
  background-color: #2eb4bd;
  border: 1px solid #2eb4bd;
  font-size: 14px;
  padding: 8px;
  border-radius: 5px;
}

/deep/ .title {
  font-size: 50px !important;
}

.titlename {
  border-top: 1px solid #000;
  line-height: 45px;
  height: 45px;
  font-size: 18px;
  text-align: center;
}

.title-name {
  border-top: 1px solid #000;
  line-height: 40px;
  height: 40px;
  font-size: 18px;
  text-align: center;
}

.title-namea {
  border-top: 1px solid #000;
  font-size: 18px;
  text-align: center;
}

.title-names {
  border-top: 1px solid #000;
  line-height: 45px;
  height: 45px;
  text-align: center;
  font-weight: 600;
  font-size: 20px;
}

.title-left {
  border-left: 1px solid #000;
}

.text {
  padding: 2px;
  line-height: 25px;
}
</style>
